/*
Copyright Polyakov Mark (qshadowp) 2012.
GNU GPLv3
*/
 
 package system.apps;
 
 import system.staros.cblock1.*;
 import java.lang.*;
 
  public class kill extends Task {
 	
 	int task_id;	

 	public void run () {
		println ("You can't run <kill> in the background");
 	}
 	
 	public int main ( String args[] ) {

 		
 		if ( args.length == 1 ) {
 		        try {
	 			task_id = Integer.parseInt(args[0], 10);
	 		} catch (NumberFormatException exception) {
	 			println ("You should specify task id as integer number");
	 			return 0;
	 		}

	 		Task task = getScheduler().getTaskByPID(task_id);
	 		if ( task == null ) {
	 			println ("No such task with PID " + Integer.toString(task_id));
	 			return 0;
	 		}
	 		
	 		Message msg = new Message ();
			msg.PID_from = this.getPID();
 			msg.PID_to = task_id;
 			msg.ID = Message.MSG_KILL;
 			putMessage (msg);
 		} else
 			println ("USAGE: kill <task_id>");
 		return 0;
 	}
 	
 }